"""
备选方案弃用
"""
# import sys
# import requests
# import json
# import re
# # PyQt5中使用的基本控件都在PyQt5.QtWidgets模块中
# from PyQt5.QtWidgets import *
# # 导入designer工具生成的login模块
# from fake_user_agent import user_agent
# from PyQt5.Qt import QMainWindow
# from PyQt5 import QtCore, QtGui, QtWidgets
#
# class Ui_widget(object):
#     def setupUi(self, widget):
#         widget.setObjectName("widget")
#         widget.resize(1066, 809)
#         self.date_label = QtWidgets.QLabel(widget)
#         self.date_label.setGeometry(QtCore.QRect(20, 10, 54, 12))
#         self.date_label.setObjectName("date_label")
#         self.from_label = QtWidgets.QLabel(widget)
#         self.from_label.setGeometry(QtCore.QRect(220, 10, 54, 12))
#         self.from_label.setObjectName("from_label")
#         self.to_label = QtWidgets.QLabel(widget)
#         self.to_label.setGeometry(QtCore.QRect(420, 10, 54, 12))
#         self.to_label.setObjectName("to_label")
#         self.pushButton = QtWidgets.QPushButton(widget)
#         self.pushButton.setGeometry(QtCore.QRect(967, 6, 75, 23))
#         self.pushButton.setObjectName("pushButton")
#         self.date_edit = QtWidgets.QLineEdit(widget)
#         self.date_edit.setGeometry(QtCore.QRect(90, 6, 113, 20))
#         self.date_edit.setObjectName("date_edit")
#         self.from_edit = QtWidgets.QLineEdit(widget)
#         self.from_edit.setGeometry(QtCore.QRect(290, 6, 113, 20))
#         self.from_edit.setObjectName("from_edit")
#         self.to_edit = QtWidgets.QLineEdit(widget)
#         self.to_edit.setGeometry(QtCore.QRect(490, 6, 113, 20))
#         self.to_edit.setObjectName("to_edit")
#         self.tableWidget = QtWidgets.QTableWidget(widget)
#         self.tableWidget.setGeometry(QtCore.QRect(20, 40, 1021, 741))
#         self.tableWidget.setObjectName("tableWidget")
#         self.tableWidget.setColumnCount(0)
#         self.tableWidget.setRowCount(0)
#
#         self.retranslateUi(widget)
#         QtCore.QMetaObject.connectSlotsByName(widget)
#
#     def retranslateUi(self, widget):
#         _translate = QtCore.QCoreApplication.translate
#         widget.setWindowTitle(_translate("widget", "高铁火车票查询"))
#         self.date_label.setText(_translate("widget", "查询日期"))
#         self.from_label.setText(_translate("widget", "出发地"))
#         self.to_label.setText(_translate("widget", "目的地"))
#         self.pushButton.setText(_translate("widget", "查询"))
#         self.tableWidget.setSortingEnabled(False)
#
# url = "https://kyfw.12306.cn/otn/resources/js/framework/station_name.js?station_version=1.8971"
# response = requests.get(url, verify=False)
# # 将车站的名字和编码进行提取
# station = re.findall(r'([\u4e00-\u9fa5]+)\|([A-Z]+)', response.text)
# station_code = dict(station)
# station_names = dict(zip(station_code.values(), station_code.keys()))
#
# class MyMainForm(QMainWindow, Ui_widget):
#     def __init__(self, parent=None):
#         super(MyMainForm, self).__init__(parent)
#         self.setupUi(self)
#         # 添加登录按钮信号和槽。注意display函数不加小括号()
#         self.pushButton.clicked.connect(self.display)
#         # 添加退出按钮信号和槽。调用close函数
#         # # self.cancel_pushButton.clicked.connect(self.close)
#         self.show()
#
#
#     def display(self):
#         # 利用line Edit控件对象text()函数获取界面输入
#         date = self.date_edit.text()
#         from_station = station_code[self.from_edit.text()]
#         to_station = station_code[self.to_edit.text()]
#
#         # date = '2021-02-20'
#         # from_station = station_code['北京']
#         # to_station = station_code['上海']
#
#         urls = "https://kyfw.12306.cn/otn/leftTicket/queryZ?"
#         cookie = 'BIGipServerpool_index=837812746.43286.0000'
#         # cookie = '''Cookie: _uab_collina=161180740889551547386455; JSESSIONID=7643AF61D00634AFE9BE64B67EBBF7FC; RAIL_EXPIRATION=1612068432945; RAIL_DEVICEID=Ufn-bQhIG3NO2xfdqot7NW-ram9ItCaiwkCCjogFMH2cTkwFuyZUiIcGWxwTlaGxNVhxMIu_oQwyguKd0SRduBIP7Yan_tu6LPhTte-wtvySRHwW9XM7GPEt29lmjy-jOx6YaZ5ufxC9ZCkiukRnSzB3B03TJRtc; BIGipServerotn=4057399562.50210.0000; BIGipServerpassport=820510986.50215.0000; route=495c805987d0f5c8c84b14f60212447d;'''
#         headers = {
#             "User-Agent": user_agent(),
#             'Cookie': cookie
#         }
#         urls = urls + "leftTicketDTO.train_date=" + date + "&leftTicketDTO.from_station=" + from_station + "&leftTicketDTO.to_station=" + to_station + "&purpose_codes=ADULT"
#         # request请求获取主页
#         r = requests.get(urls, headers=headers, verify=False)
#         r.content.decode("utf-8")
#         r.raise_for_status()  # 如果发送了一个错误的请求，会抛出异常
#         r.encoding = r.apparent_encoding
#         print(r.text)
#
#         #
#         html = json.loads(r.text)
#         print(html)
#         entries = html['data']['result']
#         datas = []
#         for i in entries:
#             item = i.split('|')  # 使用“|”进行分割
#             # 获取有票的高铁车次信息 # 获取车次信息，在3号位置 # 始发站信息在6号位置 # 终点站信息在7号位置 # 出发时间在8号位置
#             # 抵达时间在9号位置 # 经历时间在10号位置 # 特别注意，商务座在32或25位置 # 一等座信息在31号位置 # 二等座信息在30号位
#             if (item[30] != "" and item[30] != "无") or (item[31] != "" and item[31] != "无") or (item[32] != "" and item[32] != "无") or (item[25] != "" and item[25] != "无"):
#                 ii = [item[3], station_names[item[6]], station_names[item[7]], item[8], item[9], item[10],
#                       item[32] or item[25],
#                       item[31], item[30]]
#                 datas.append(ii)
#
#         self.tableWidget.setRowCount(len(datas))#设置列表行数
#         self.tableWidget.setColumnCount(len(datas[0]))#设置列表列数
#         self.tableWidget.setVerticalHeaderLabels(['1', '2', '3'])#设置列表行数表头
#         self.tableWidget.setHorizontalHeaderLabels(['车次', '出发车站', '达到车站', '出发时间', '到达时间', '历时', '商务座', '一等座', '二等座'])#设置列表列数表头
#         self.tableWidget.setStyleSheet("QHeaderView::section{background:skyblue;}")#表头加点颜色
#         for i, row in enumerate(datas):#列表数据
#             for j, col in enumerate(row):
#                 item = QTableWidgetItem(col)
#                 self.tableWidget.setItem(i, j, item)
#
# if __name__ == "__main__":
#     # 固定的，PyQt5程序都需要QApplication对象。sys.argv是命令行参数列表，确保程序可以双击运行
#     app = QApplication(sys.argv)
#     # 初始化
#     myWin = MyMainForm()
#     # 将窗口控件显示在屏幕上
#     myWin.show()
#     # 程序运行，sys.exit方法确保程序完整退出。
#     sys.exit(app.exec_())
